package com.liunian.subject.common.generator;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;

public class CodeGenerator {
    public static void main(String[] args) {
        generator();
    }


    private static void generator() {

        FastAutoGenerator.create(new DataSourceConfig
                        .Builder("jdbc:mysql://localhost:3306/cfp?useSSL=false", "root", "root"))
                .globalConfig(builder ->
                                builder
                                        .outputDir(System.getProperty("user.dir") + "/subject-common/src/main/java")
                                        .enableSwagger()
                                        .author("wwt")
                                        .dateType(DateType.ONLY_DATE) // 时间策略
                                        .commentDate("yyyy-MM-dd") // 注释日期
//                                .fileOverride()
                                        .disableOpenDir()

                )

                .packageConfig(builder -> builder.parent("com.liunian.media.hub.core")
                        .entity("domain.entity")
                        .mapper("mapper")
                        .service("service")
                        .serviceImpl("service.impl")
                        .controller("controller")
                )
                .strategyConfig(builder ->
                                builder
                                        .addInclude("record_bccr")
                                        .entityBuilder()
                                        .idType(IdType.AUTO)
                                        .enableLombok()
                                        .enableTableFieldAnnotation()
                                        .enableFileOverride()
                                        .mapperBuilder()
                                        .enableBaseResultMap()
                                        .superClass(BaseMapper.class)
                                        .enableBaseColumnList()
                                        .formatMapperFileName("%sMapper")
                                        .formatXmlFileName("%sMapper")
                                        .serviceBuilder()
                                        .formatServiceFileName("I%sService")
                                        .formatServiceImplFileName("%sServiceImpl")
                                        .controllerBuilder()
                                        .enableRestStyle()
                                        .enableHyphenStyle()
                                        .formatFileName("%sController")
                )
                .templateEngine(new VelocityTemplateEngine())
                .templateConfig(builder -> builder.controller("controller.java"))
//                .injectionConfig(builder -> builder
//                        .customFile(new CustomFile.Builder().fileName("DTO.java").templatePath("entityDTO.java.vm").packageName("domain.dto").build())
//                        .customFile(new CustomFile.Builder().fileName("VO.java").templatePath("entityVO.java.vm").packageName("domain.vo").build())
//                        .customFile(new CustomFile.Builder().fileName("Wrapper.java").templatePath("wrapper.java.vm").packageName("domain.wrapper").build()))
                .execute();
    }
}

